package com.authservice.authservice.controller;

import com.authservice.authservice.domain.dto.AuthCodeDTO;
import com.authservice.authservice.domain.dto.UpdatePasswordDTO;
import com.authservice.authservice.service.AuthService;
import com.commonmodule.commonmodule.util.R;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @author zxb
 * @version 1.0
 * @date 2025-04-07 10:10
 */
@Slf4j
@RestController
@RequestMapping("/auth")
public class AuthController {


    @Resource
    private AuthService authService;

    /**
     * 账号密码登录
     * @param account
     * @param password
     * @return
     */
    @PostMapping("/login")
    public R<String> login(@NotNull @RequestParam("account") String account, @NotNull @RequestParam("password") String password) {
        return authService.login(account,password);
    }


    /**
     * 退出登录
     * @param request
     * @return
     */
    @PostMapping("/exit")
    public R<?> exit(HttpServletRequest request){
        String token = request.getHeader("token");
        return authService.exit(token);
    }


    /**
     * 修改密码
     * @param updatePasswordDTO
     * @return
     */
    @PostMapping("/updatePassword")
    public R<?> updatePassword(@RequestBody UpdatePasswordDTO updatePasswordDTO) {

        return authService.updatePassword(updatePasswordDTO);

    }


    /**
     * 发送验证码
     * @param authCodeDTO
     * @return
     */
    @PostMapping("/note")
    public R<?> note(@RequestBody AuthCodeDTO authCodeDTO) {
        return authService.note(authCodeDTO.getPhone(), authCodeDTO.getType());
    }


    /**
     * 注册
     * @param authCodeDTO
     * @return
     */
    @PostMapping("/enroll")
    public R<?> enroll(@RequestBody AuthCodeDTO authCodeDTO){
        return authService.enroll(authCodeDTO);
    }


    /**
     * 验证码登录
     * @param authCodeDTO
     * @return
     */
    @PostMapping("/authCodeLogin")
    public R<?> authCodeLogin(@RequestBody AuthCodeDTO authCodeDTO){
        return authService.authCodeLogin(authCodeDTO);
    }


}
